<template>
  <div class="map-layers-cut">
    <div class="map-layers-div" :class="activeTab == index ? 'map-layers-div-active' : 'map-layers-div'" v-for="(item,index) in tabList"
         @click="changeTab(index,item)">
      <img class="map-layers-img" :src="item.icon" alt="">
      <span class="map-layers-title">{{item.title}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "mapSwitch",
  data() {
    return {
      tabList: [],
      activeTab: 0
    }
  },
  created() {
    this.activeTab = this.defaultTab
    this.tabList = this.defaultList
  },
  // 获取子组件传过来的激活tab
  props: {
    defaultTab: {
      type: Number,
      default: 0
    },
    defaultList: {
      type: Array,
      default: function () {
        return [
          {
            title: '地图', icon: require('@/assets/map/map-switch-vec.png'), layers: ['vec']
          },
          {
            title: '影像', icon: require('@/assets/map/map-switch-img.png'), layers: ['img_cache_world', 'img_cva_cache_fengfeng']
          },
          {
            title: '三维',
            icon: require('@/assets/map/map-switch-3d.png'),
            layers: ['DEM_NoCity', 'img_cache_world', 'img_cva_cache_fengfeng']
          }
        ]
      }
    }
  },
  methods: {
    changeTab(index, item) {
      // 改变选中的底部tab样式
      this.activeTab = index
      // 将点击Tab的事件暴露给父组件
      this.$emit('on-click', index, item)
    }
  }
}
</script>

<style lang="scss"  scoped>
.map-layers-cut {
  width: 240px;
  height: 80px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  border-radius: 4px;
  border: 1px solid #005aca;
  background-color: #F5F7FA;
  color: #909399;

  .map-layers-div {
    width: 65px;
    height: 65px;
    margin: 0 5px;
    position: relative;
    border: 1px solid #f3f3f3;
    box-sizing: border-box;

    .map-layers-img {
      width: 100%;
      height: 100%;
      position: absolute;
      z-index: 1;
    }

    .map-layers-title {
      display: block;
      position: absolute;
      z-index: 9;
      left: 0;
      bottom: 0;
      padding: 2px 6px;
      background-color: #111111;
      color: #ffffff;
    }

    &:hover {
      cursor: pointer;
      .map-layers-title {
        background-color: #0081ff;
      }
    }
  }

  .map-layers-div-active {
    border: 1.5px solid #0081ff;
    box-sizing: border-box;

    .map-layers-title {
      background-color: #0081ff;
    }
  }
}
</style>